<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>promise初使用之盒子定时器</title>
    <style>
        .box{
            width: 100px;
            height: 100px;
            margin-bottom: 10px;
        }
    </style>
</head>
<body>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>

    <script>
        var boxs = document.querySelectorAll('.box');

        // 第一个盒子
        var p_box1 = new Promise((resolve,reject)=>{
            setTimeout(()=>{
                boxs[0].style.background = "red";
                resolve();
            },1000)
        })

        // 第二个盒子
        var p_box2 = p_box1.then(()=>{
            var p_box2 = new Promise((resolve,reject)=>{
                setTimeout(()=>{
                    boxs[1].style.background = 'pink';
                    resolve();
                },1000);
            })
            return p_box2;
        })

        // 第三个盒子
        var p_box3 = p_box2.then(()=>{
            var p_box3 = new Promise((resolve,reject)=>{
                setTimeout(()=>{
                    boxs[2].style.background = 'blue';
                    resolve();
                },1000);
            })
            return p_box3
        })

        // 第四个盒子
        var p_box4 = p_box3.then(()=>{
            var p_box4 = new Promise((resolve,reject)=>{
                setTimeout(()=>{
                    boxs[3].style.background = 'green';
                    resolve();
                },1000)
            });
            return p_box4
        })

        // 第五个盒子
        p_box4.then(()=>{
           new Promise((resolve,reject)=>{
                setTimeout(()=>{
                    boxs[4].style.background = "orange";
                },1000)
            })
        })
    </script>
</body>
</html>